﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

using com.tiyma.model;
using com.tiyma.components;
using com.tiyma.common;

namespace com.tiyma.web
{
    public partial class Default : BasePage
    {
        BookManager m_book_mgr = new BookManager();

        string m_cur_template = "<div class=\"curRead\"><div class=\"btitle\">最近阅读</div><div class=\"blist\">{0}</div></div>";

        string m_cur_item_template = "<ul {10}><li class=\"ro0\">[<a href=\"/bookList.aspx?k={0}&t=3\" target=\"_blank\">{1}</a>]</li><li class=\"ro1\"><a href=\"/book/{3}/{2}/\" class=\"f14\" target=\"_blank\">{4}</a></li><li class=\"ro2\"><a href=\"chapter/{3}/{5}/\" target=\"_blank\">{6}</a></li><li class=\"ro3\"><a href=\"/bookList/2/{7}/1/\" target=\"_blank\">{8}</a></li><li class=\"ro4\">{9}</li></ul>";

        public string m_cur_list = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
            //BindCurRead();
        }

        protected void Page_PreRender(object sender, EventArgs e)
        {
            if (this.Master is Common)
            {
                Common master = (Common)this.Master;
                master.SetCssFile("/style/main.css");
            }
        }

        /// <summary>
        /// 绑定最近阅读
        /// </summary>
        private void BindCurRead()
        {
            BookManager t_book_mgr=new BookManager();
            try
            {
                List<BookInfo> t_list = t_book_mgr.GetCurReadBook();

                if (t_list != null && t_list.Count>0)
                {
                    StringBuilder t_sb = new StringBuilder();
                    int t_index = 0;
                    foreach (BookInfo t_book in t_list)
                    {
                        t_sb.AppendFormat(m_cur_item_template, HttpUtility.UrlEncode(t_book.BookCategory),
                            t_book.BookCategory,
                            t_book.BookId,
                            t_book.SiteId,
                            t_book.BookName,
                            t_book.LastUpdateChapterId,
                            t_book.LastUpdateChapterName,
                            HttpUtility.UrlEncode(t_book.AuthorName),
                            t_book.AuthorName,
                            t_book.LastUpdateTime.ToString("yyyy-MM-dd"),
                            (t_index==t_list.Count-1 || t_index==4)?"class=\"noline\"":""
                            );
                        t_index++;
                        if (t_index == 5)
                            break;
                    }

                    m_cur_list = string.Format(m_cur_template, t_sb.ToString());
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("绑定最近阅读失败" + ex.ToString());
            }
        }
    }
}
